var digit = ["", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
var unit = ["", "万", "亿"];
var base = ["", "拾", "佰", "仟"];

const add4 = (num) => {
  const arr = num.toString().split("");
  while (arr.length < 4) {
    // 4是一个数量级
    arr.unshift(0);
  }
  return arr;
};

function digInt(num) {
  let s = "";

  for (let i = 0; i < unit.length && num > 0; i++) {
    const $number = num % 10000; // 除以一万取余，这个数补零至四位。填入“个十百千”
    console.log("number", $number);
    const format = add4($number); // 前面补零够4位
    console.log(format);
    // ********************************字符串处理开始**********************************
    // 对号入座就好了, 这里只是简单的字符串判断处理，更细节的处理无需研究了。借用开源方法去完成吧
    const str_0 = Number(format[0]) !== 0 ? digit[format[0]] + "千" : "零";
    const str_1 = Number(format[1]) !== 0 ? digit[format[1]] + "百" : "零";
    const str_2 = Number(format[2]) !== 0 ? digit[format[2]] + "十" : "零";
    const str_3 = Number(format[3]) !== 0 ? digit[format[3]] + "" : "";

    // 先去除中间的零，  再去除开头的零
    s = (str_0 + str_1 + str_2 + str_3).replace(/零{1,}/, "零");
    unit[i] + s;
    // ********************************字符串处理完毕**********************************

    //  再次给 num 赋值，开始下一次循环
    num = Math.floor(num / 10000);
  }
  s.replace(/^零{1,}/, "");
  return s;
}

const result = digInt(10801229300);

console.log(result);
